<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"><?php echo $this->translate('添加客户分类'); ?></h4>
    </div>
    <?php
    $form = $this->form;
    $form->prepare();

    $form->get('customerCategoryCode')->setAttributes([
        'placeholder' => $this->translate('客户分类编码')
    ]);

    $form->get('customerCategoryName')->setAttributes([
        'placeholder' => $this->translate('客户分类名称')
    ]);

    $form->get('customerCategorySort')->setAttributes([
        'placeholder' => $this->translate('客户分类排序')
    ]);

    ?>
    <?php echo $this->form()->openTag($form); ?>
    <div class="modal-body box-body">
        <div class="form-group">
            <label  class="col-sm-2 control-label"><?php echo $this->translate('客户分类编码'); ?><span class="must_add_value">*</span></label>
            <div class="col-sm-3">
                <?php echo $this->formElement($form->get('customerCategoryCode')); ?>
                <?php echo $this->formElementErrors($form->get('customerCategoryCode'), ['class'=>'error-message']); ?>
            </div>
        </div>

        <div class="form-group">
            <label  class="col-sm-2 control-label"><?php echo $this->translate('客户分类名称'); ?><span class="must_add_value">*</span></label>
            <div class="col-sm-6">
                <?php echo $this->formElement($form->get('customerCategoryName')); ?>
                <?php echo $this->formElementErrors($form->get('customerCategoryName'), ['class'=>'error-message']); ?>
            </div>
        </div>

        <div class="form-group">
            <label  class="col-sm-2 control-label"><?php echo $this->translate('排序'); ?><span class="must_add_value">*</span></label>
            <div class="col-sm-3">
                <?php echo $this->formElement($form->get('customerCategorySort')); ?>
                <?php echo $this->formElementErrors($form->get('customerCategorySort'), ['class'=>'error-message']); ?>
            </div>
        </div>

    </div>

    <div>
        <div class="box-footer">
            <button type="submit" class="btn btn-primary col-md-offset-2"><i class="fa fa-check"></i> <?php echo $this->translate('保存客户分类'); ?></button>
        </div>
    </div>
    <?php echo $this->form()->closeTag(); ?>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                customerCategoryCode: {
                    required: true
                },
                customerCategoryName: {
                    required: true
                },
                customerCategorySort: {
                    required: true,
                    number: true,
                    min: 1
                }
            },
            messages: {
                customerCategoryCode: {
                    required: "<?php echo $this->translate('客户分类编码不能为空！'); ?>"
                },
                customerCategoryName: {
                    required: "<?php echo $this->translate('客户分类名称不能为空！'); ?>"
                },
                customerCategorySort: {
                    required: "<?php echo $this->translate('排序不能为空！'); ?>",
                    number: "<?php echo $this->translate('排序必须为数字！'); ?>",
                    min: "<?php echo $this->translate('排序最小为1！'); ?>"
                }
            },
            submitHandler: function () {
                $.ajax({
                    url: '<?php echo $this->url('customer-category', ['action' => 'ajaxAddCustomerCategory']); ?>',
                    type: 'post',
                    dataType: 'json',
                    data: $('#<?php echo $form->getName(); ?>').serialize(),
                    success: function (data) {
                        if (data.status === 'ok') {
                            updateCustomerCategorySelect(data.message);
                        }
                    }
                })
            }
        })
    });
</script>
